<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }
        .nav {
            margin: 0px auto;
            width: 600px;
            height: 75px;
        }
        .nav input {
            width: 400px;
            height: 50px;
            border-radius: 5px;
            line-height: 15px;
        }
        .nav button {
            width: 200px;
            height: 50px;
            background-color: orange;
            color: white;
            border-radius: 5px;
        }
        .nav button:active {
            background-color: gray;
        }
        .container {
            display: flex;
            justify-content: center;
        }
        h3 {
            width: 300px;
            background-color: black;
            color: white;
            line-height: 40px;
            text-align: center;
        }
        .row {
            width: 300px;
            display: flex;
        }
        .row span {
            font-size: 20px;
            width: 200px;
            padding: 5px 5px;
        }
        .row button {
            width: 50px;
            height: 35px;
        }
        .row input {
            width: 20px
        }
    </style>
</head>
<body>
    <div class="nav">
        <input type="text"><button onclick="newJob()">新建任务</button>
    </div>
    <div class="container">
        <div class="todo">
            <h3>未完成</h3>
            <div class="row">
            </div>
        </div>
        <div class="done">
            <h3>已完成</h3>
        </div>
    </div>

    <script>
        function newJob() {
            //获取输入框中的内容
            let text = document.querySelector('.nav input')
            let text_info = text.value;
            if (text_info == '') return;
            //创建新的row元素
            let row = document.createElement('div')
            row.className = 'row'
            //创建row中的checkbox元素
            let checkbox = document.createElement('input')
            checkbox.type = 'checkbox'
            //创建row中的span元素
            let span = document.createElement('span')
            span.innerHTML = text_info
            let button = document.createElement('button')
            button.innerHTML = '删除'
            let todo = document.querySelector('.todo')
            row.append(checkbox)
            row.appendChild(span)
            row.appendChild(button)
            todo.appendChild(row)
            text.value = ''
            button.onclick = function() {
                let parent = this.parentNode
                let grandparen = parent.parentNode
                grandparen.removeChild(parent)
            }
            let checkboxs = document.querySelectorAll('.row input')
            for (let checkbox of checkboxs) {
                checkbox.onclick = function() {
                    let parent = this.parentNode
                    let node
                    if (this.checked) {
                        node = document.querySelector('.done')
                    }else {
                        node = document.querySelector('.todo')
                    }
                    node.appendChild(parent)
                }
            }
        }        
    </script>
</body>
</html>